//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<RenderManager.h>
///	@path	~/src/graphics/
///	@date	2007/11/01
///	@desc	Render integration.

#pragma once

#include "xeres.h"

#include "lib/utilities/dict.h"

#include "graphics/RenderPipeline.h"

namespace xeres {

	/*!
		\class	RenderManager
		\brief	Manages render contents.

		\sa IRenderer
	*/
	class RenderManager : public RenderPipeline
	{
	protected:

		/// \name Constructor & Destructor
		//@{

		/// \ctor
		RenderManager( void );

		/// \dtor
		~RenderManager( void );

		//@}

		/// \name Initialization & Finalization
		//@{

		/*!
			\brief		Initialize render manager.
		*/
		void Initialize( void );

		/*!
			\brief		Finalize render manager.
		*/
		void Finalize( void );

		//@}

		/// \name Render Manipulation
		//@{

		/*!
			\brief		Render pipeline with batches.
		*/
		void Render( void );

		//@}
		
	public:

		using RenderPipeline::GetMainPass;

		/// \name Overlay & Wallpaper
		//@{

		/// \brief		Set overlay as a canvas slot & config slot count.
		void SetOverlaySlot( size_t count );

		/// \brief		Set overlay canvas.
		void SetOverlayCanvas( size_t slot , RefWeak<ICanvas> canvas );

		//@}

		/// \name Shading Mode
		//@{

		/*!
			\brief		Change a shading mode pipeline.
						Currently either can be 'deferred' or 'forward'.
		*/
		void ChangeShadingMode( const WString& mode );

		/*!
			\brief		Get current shading mode.
		*/
		const WString& GetShadingMode( void ) const { return m_shadingMode; }

		//@}

		/// \name Effect Loading
		//@{

		typedef function<RefPass<IEffect>(const WString&,RefWeak<IEffectPool>,RenderManager&)> EffectLoader;
		typedef function<RefPass<IShader>(const WString&,RenderManager&)> ShaderLoader;

		/// \brief		Register an effect loader.
		void RegisterEffectLoader( const WString& name , EffectLoader loader );

		/// \brief		Deregister effect loader.
		void DeregisterEffectLoader( const WString& name );

		/// \brief		Register an shader loader.
		void RegisterShaderLoader( const WString& name , ShaderLoader loader );

		/// \brief		Deregister shader loader.
		void DeregisterShaderLoader( const WString& name );

		/// \brief		Query loaded effect.
		RefWeak<IEffect> QueryEffect( const WString& url );

		/// \brief		Query loaded shader.
		RefWeak<IShader> QueryShader( const WString& url );

		/// \brief		Load effect.
		RefPass<IEffect> LoadEffect( const WString& url , RefWeak<IEffectPool> pool , bool cache );

		/// \brief		Load shader.
		RefPass<IShader> LoadShader( const WString& url , bool cache );

		//@}

	private:

		/// \brief	Load shader from loaded effect list.
		static RefPass<IShader> DefaultShaderLoader( const WString& url , RenderManager& rm );

		//@ data

		// render
		WString				m_shadingMode;

		// effect loaders
		std::vector< std::pair<WString,EffectLoader> >	m_effectLoaders;

		// shader loaders
		std::vector< std::pair<WString,ShaderLoader> >	m_shaderLoaders;

		// loaded effects
		dict< WString,Ref<IEffect> >	m_loadedEffects;

		// loaded shader
		dict< WString,Ref<IShader> >	m_loadedShaders;
	};

} // namespace xeres
